package ${packageName}.service.impl;

import com.github.pagehelper.PageHelper;
import ${packageName}.entity.${className};

import ${packageName}.bo.${lowerClassName}.dto.input.${className}InputDto;
import ${packageName}.bo.${lowerClassName}.dto.query.${className}QueryDto;
import ${packageName}.bo.${lowerClassName}.vo.${className}Vo;
import com.github.pagehelper.PageInfo;
import ${packageName}.mapper.${className}Mapper;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import ${packageName}.service.I${className}Service;
import javax.annotation.Resource;



@Service
@Slf4j
public class ${className}ServiceImpl implements I${className}Service  {


    @Resource
    private ${className}Mapper ${lowerClassName}Mapper;



     /**
     * 新增修改方法
     * @param ${lowerSaveClassName}
     */
    @Override
    public ${className}Vo saveOrUpdate(${saveClassName} ${lowerSaveClassName}) {
        ${className} ${lowerClassName}=new ${className}();
        BeanUtils.copyProperties(${lowerSaveClassName},${lowerClassName});
        if(${lowerSaveClassName}.get${upPrimary}()==null){
             ${lowerClassName}=save(${lowerClassName});
        }else{
              ${lowerClassName}=update(${lowerClassName});
        }

         ${className}Vo  ${lowerClassName}Vo=new ${className}Vo();
         BeanUtils.copyProperties(${lowerClassName},${lowerClassName}Vo);
         return ${lowerClassName}Vo;
    }



    /**
     * 新增
     * @param ${lowerClassName}
     */
    @Override
    public ${className} save(${className} ${lowerClassName}) {
       ${lowerClassName}Mapper.insertSelective(${lowerClassName});
        return ${lowerClassName};
    }


     /**
     * 修改
     * @param ${lowerClassName}
     */
    @Override
    public ${className} update(${className} ${lowerClassName}) {
        ${lowerClassName}Mapper.updateByPrimaryKeySelective(${lowerClassName});
        return ${lowerClassName};
    }



     /**
     * 通过主键 查询对应对象
     * @param ${primaryClassName}
     * @return
     */
    @Override
    public ${className} getByPrimary(${primaryClassType} ${primary}) {
        ${className} ${lowerClassName}= ${lowerClassName}Mapper.selectByPrimaryKey(${primary});
        return ${lowerClassName};
    }





    /**
     * 通过主键 查询对应对象Vo
     * @param ${primaryClassName}
     * @return
     */
    @Override
    public ${className}Vo getVoByPrimary(${primaryClassType} ${primary}) {
        ${className} ${lowerClassName}= ${lowerClassName}Mapper.selectByPrimaryKey(${primary});
        ${className}Vo  ${lowerClassName}Vo=new ${className}Vo();
        BeanUtils.copyProperties(${lowerClassName},${lowerClassName}Vo);
        return ${lowerClassName}Vo;
    }


     /**
     * 根据主键删除对象
     * @param ${primaryClassName}
     */
     @Override
     public void deleteByPrimary(${primaryClassType} ${primary}) {
        ${lowerClassName}Mapper.deleteByPrimaryKey(${primary});
     }

    /**
    * 分页查询
    * @param ${lowerClassSearchName} 查询条件
    * @return
    */
    @Override
    public PageInfo<${classPageName}> getPage(${classSearchName} ${lowerClassSearchName}) {
        PageHelper.startPage(${lowerClassSearchName}.getPageNo(), ${lowerClassSearchName}.getPageSize());
        List<${classPageName}> list=${lowerClassName}Mapper.getPage(${lowerClassSearchName});
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }


   /**
     * 根据对象查询
     * @param ${lowerClassName} 根据对象查询
     */
     @Override
     public List<${className}> getList(${className} ${lowerClassName}){
       return ${lowerClassName}Mapper.select(${lowerClassName});
     }


}